public class LC_24 {
}
class Solution {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode slow = head, mid = head.next, fast = head.next.next;
        head = head.next;
        while(mid != null){
            mid.next = slow;
            if(fast != null && fast.next != null){
                slow.next = fast.next;
            }else{
                slow.next = fast;
            }

            slow = fast;
            if(fast != null){
                mid = fast.next;
            }else{break;}


            if(fast.next != null){
                fast = fast.next.next;
            }
        }
        return head;

    }
}
